package cn.bone.ou.scheduled;

import org.quartz.Trigger;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;

import javax.annotation.Resource;

@Configuration
public class QuartzConfig {

    @Resource(name = "voteTrigger")
    private Trigger voteTrigger;
    @Resource(name = "committeeTrigger")
    private Trigger committeeTrigger;
    @Resource(name = "loggerTrigger")
    private Trigger loggerTrigger;

    @Bean(name = "schedulerFactory")
    public SchedulerFactoryBean schedulerFactoryBean(){
        SchedulerFactoryBean bean = new SchedulerFactoryBean();
        // 覆盖已存在的任务
        bean.setOverwriteExistingJobs(true);
        // 延时启动定时任务，避免系统未完全启动却开始执行定时任务的情况
        bean.setStartupDelay(15);
        // 注册触发器
        bean.setTriggers(
                voteTrigger,
                committeeTrigger,
                loggerTrigger
        );
        return bean;
    }

}
